
import CommonModel from '../../../../hrpub/common/model';
import {hrAjax} from '../../../../hrpub/common/utils/utils';

import download from '../../../../hrpub/common/utils/download/download';

import {toast} from 'nc-lightapp-front';
import unzip from "../../../../hrpub/common/utils/unZipAndDecrypt";

class ScaModel extends CommonModel {
    constructor() {
        super();
    }
    name = 'sca'
    data = {
        language: {},
        context: {},
        staffAreaMap: {}, // 主页面的map数据, 写在这里是为了以防之后有扩展，或变为动态
        page: 'main', // 当前页面main entry leave regular
        orgValue: {
            entry: null,
            leave: null,
            regular: null
        }, // 组织参照值
        pageInfo: {
            pageIndex: 1,
            pageSize: 10,
            total: 0,
            totalPage: 1
        },
        exportModal: false, // 导出弹窗
        exportValue: null, // 导出参照的值,
        allPks: [], // 表格得所有主键
    }
    sync = {
        ...this.sync,
        // 当多语返回时，设置员工三个卡的文字数据
        updateStaffAreaMap(state, payload) {
            return {
                ...state,
                staffAreaMap: {
                    entry: {
                        title: state.language['gx6008-000124'], // '入职分析',
                        iconClass: 'add-staff'
                    },
                    leave: {
                        title: state.language['gx6008-000125'], // '离职分析',
                        iconClass: 'leave-staff'
                    },
                    regular: {
                        title: state.language['gx6008-000126'], // '转正分析',
                        iconClass: 'regular-staff'
                    }
                }
            }
        }
    }
    async = {
        // 获取表格数据
        getMainTableData(dispatch, state, payload) {
            return hrAjax({
                url: '/nccloud/hrtrn/psnchg/QueryPsnChgAction.do',
                body: payload.postData
            });
        },
        // 导出
        doExport(dispatch, state, payload) {
            download({
                url: '/nccloud/hrtrn/psnchg/ExportPsnChgAction.do',
                method: 'post',
                body: payload.postData,
                enctype: 2,
                onResult: (body) => {
                    let res = unzip(body.innerText);
                    res = JSON.parse(res)
                    if(!res.success){
                        toast({
                            color: 'danger',
                            content: res.error.message
                        });
                    }
                }

            });
        }
    }
}


export default new ScaModel();